package com.xyd.auth.contoller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xyd.auth.service.ISysMenuService;
import com.xyd.common.result.GlobalResultClass;
import com.xyd.model.system.SysMenu;
import com.xyd.model.system.vo.AssignMenuVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name="菜单管理")
@RestController
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {
   @Autowired
   private ISysMenuService sysMenuService;

   @Operation(summary = "获取菜单")
   @GetMapping("/findNodes")
   public GlobalResultClass<List<SysMenu>> findNodes(){
       List<SysMenu> nodes = sysMenuService.findNodes();
       return GlobalResultClass.ok(nodes);
   }

   @Operation(summary = "添加菜单")
   @PostMapping("/save")
   public GlobalResultClass save(@RequestBody SysMenu sysMenu){
       sysMenuService.save(sysMenu);
       return GlobalResultClass.ok();
   }

   @Operation(summary = "修改菜单")
   @PutMapping("/updateById")
   public GlobalResultClass updateById(@RequestBody SysMenu sysMenu){
        sysMenuService.updateById(sysMenu);
        return GlobalResultClass.ok();
   }
   @Operation(summary = "根据id删除菜单")
   @DeleteMapping("/deleteById/{id}")
   public GlobalResultClass deleteById(@PathVariable  Long id){
       sysMenuService.deleteById(id);
       return GlobalResultClass.ok();
   }

   @Operation(summary = "根据角色获取菜单")
   @GetMapping("/toAssign/{roleId}")
   public GlobalResultClass toAssign(@PathVariable Long roleId){
       List<SysMenu> list = sysMenuService.findSysMenuByRoleId(roleId);
       return GlobalResultClass.ok(list);
   }

   @Operation(summary = "根据角色id分配菜单")
   @PostMapping("/doAssign")
   public GlobalResultClass doAssign(@RequestBody AssignMenuVO assignMenuVO){
       sysMenuService.doAssign(assignMenuVO);
       return GlobalResultClass.ok();
   }
}
